import Vue from 'vue'
import Vuex from 'vuex'
import axios from 'axios'

import menuStore from './modules/menu_store'
import companyName from './modules/company_name'
import Values from './modules/value'
import Work from './modules/work'
import Economy from './modules/economy'
import Company from './modules/company'
Vue.use(Vuex)

const store =  new Vuex.Store({
    state: {
        timeindex: 0,
        historyLength: 0
    },
    getters: {
        dataSplit: state => {
            return state.todos.filter(todo => todo.done)
        },
        
    },
    mutations: { //变异
        timeAdd(state,val,) {
           setInterval(() => {
            state.timeindex++;
            if (state.timeindex == val) {
                state.timeindex = 0;
            }
          }, 3000);

        }
    },
    actions: {
        timeAdd({  commit }, val) { //时间变化值
            commit('timeAdd', val)
        },
        dformat(num) { //数字分组
            var result = '';
            var _flag = true;
            num = (num || 0).toString();
            if (num.substring(0, 1) == '-') {
                num = num.slice(1);
                _flag = false;
            }
            while (num.length > 3) {
                result = ',' + num.slice(-3) + result;
                num = num.slice(0, num.length - 3);
            }
            if (num) {
                result = num + result;
            }
            if (_flag) {
                return result;
            } else {
                return '-' + result;
            }
        },
        pointFormat(num) { //带小数点的保留
            var num = (num || 0).toString(),
                result = '';
            //判断是否带小数点
            if (num.split('.')[1]) {
                var numInt = num.split('.')[0],
                    numFlo = num.split('.')[1];
                result = this.dformat(numInt) + '.' + numFlo
            } else {
                result = this.dformat(num);
            }
            return result;
        },

    },
    modules: {
        menuStore,
        Values,
        companyName, //new
        Work,
        Economy,
        Company, //企业
        // API
    }
})
export default store;